package com.nanachi.feign.core.context;

import lombok.Data;
import lombok.Getter;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.cloud.context.named.NamedContextFactory;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author yuhongtai
 * 存放不同配置的子容器
 */
public class SimpleFeignContext extends NamedContextFactory<SimpleFeignSpecification> {


    public SimpleFeignContext(Class<?> defaultConfigType, String propertySourceName, String propertyName) {
        super(defaultConfigType, propertySourceName, propertyName);
    }

    /**
     * 通过容器名字和类型，获取配置feignClient实例
     * @param name
     * @param type
     * @param <T>
     * @return
     */
    public <T> T getInstanceWithContextName(String name, Class<T> type) {
        try {
            return BeanFactoryUtils.beanOfType(getContext(name), type);
        } catch (BeansException ex) {
            return null;
        }
    }


}
